package com.config.ser.mapper;

import com.config.ser.model.CloudConfigDO;
import com.config.ser.vo.CheckMD5VO;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CloudConfigMapper {

    @Select("SELECT * FROM cloud_config WHERE server_name=#{serverName};")
    CheckMD5VO checkMD5(@Param("serverName")String serverName);

    @Insert("INSERT INTO cloud_config(server_name, md5, value) values(#{cloudConfigDO.serverName}, #{cloudConfigDO.md5}, #{cloudConfigDO.value})")
    int addConfig(@Param("cloudConfigDO") CloudConfigDO cloudConfigDO);

    @Select("SELECT id, server_name AS serverName, value, md5 FROM cloud_config WHERE server_name=#{serverName};")
    CloudConfigDO selectConfig(@Param("serverName")String serverName);

    @Select("SELECT * FROM cloud_config WHERE id!=#{id} and server_name=#{serverName};")
    CloudConfigDO selectUpdRepeatConfig(@Param("serverName") String serverName, @Param("id") Integer id);

    @Update("UPDATE cloud_config set server_name = #{cloudConfigDO.serverName}, md5 = #{cloudConfigDO.md5}, value = #{cloudConfigDO.value} WHERE id=#{cloudConfigDO.id};" )
    int updConfig(@Param("cloudConfigDO") CloudConfigDO cloudConfigDO);

    @Select("SELECT id, server_name AS serverName, value, md5 FROM cloud_config;")
    List<CloudConfigDO> selectAllConfig();

    @Delete("DELETE FROM cloud_config WHERE server_name=#{serverName};")
    int delConfig(@Param("serverName") String serverName);

    @Select("SELECT id, server_name AS serverName, value, md5 FROM cloud_config WHERE id=#{id};")
    CloudConfigDO selectConfigById(@Param("id") Integer id);
}
